/*
 * @file     g_vbat_ctr.h
 * @brief    This file contains all the functions prototypes for the lpm reg control firmware library.
 *
 * Change Logs:
 * Date           Author             Version        Notes
 * 2020-12-16     wangjingfan        V1.0.0         the first version
 */

#ifndef __G_VBAT_CTR_H__
#define __G_VBAT_CTR_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "g_1903.h"
#include "g_system.h"

/***********************  LPM Accesscode Unit Block  **************************/
#define ACCESSCODE1                                 ((uint8_t)0x55)
#define ACCESSCODE2                                 ((uint8_t)0xAA)
#define ACCESSCODE3                                 ((uint8_t)0x17)

/**
 * @method G_LPM_AccessCode
 * @brief  LPM module enabling control
 * @param  status: new state of the RTC region operational availability
 *                 This parameter can be ENABLE or DISABLE
 * @retval None
 */
__STATIC_INLINE void G_LPM_AccessCode(G_FunctionalState status)
{
    /* Write access code "0x55->0xaa->0x17" to set or clear "access_en" */
    MLPM->ACCESS_CODE.reg = ACCESSCODE1;
    MLPM->ACCESS_CODE.reg = ACCESSCODE2;
    MLPM->ACCESS_CODE.reg = ACCESSCODE3;

    if (MLPM->ACCESS_EN.reg == status)
        return;

    /* This bit can only be set/cleared after access code sequence check pass */
    MLPM->ACCESS_EN.reg = status;
}

/**
 * @method G_LPM_RegisterClk
 * @brief  LPM module register clk control
 * @param  status: new state of the RTC region operational availability
 *                 This parameter can be ENABLE or DISABLE
 * @retval None
 */
__STATIC_INLINE void G_LPM_RegisterClk(G_FunctionalState status)
{
    if (MLPM->CLK_CTRL.reg == status)
        return;

    MLPM->CLK_CTRL.reg = status;
}

#ifdef __cplusplus
}
#endif

#endif

/************************ (C) COPYRIGHT GKT *****END OF FILE****/
